package red_book.year2024.month4;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

/**
 * 4 2
 * 1 2 3 4
 * 3 4 2 1
 *
 * 10
 * @author liangchuangchuang
 */

public class GoodSulo {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int n=scanner.nextInt();
        int m=scanner.nextInt();
        int [][]arr=new int[2][n];
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < n; j++) {
                arr[i][j]=scanner.nextInt();
            }
        }
        scanner.close();
        List<int[]> list=new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(new int[]{arr[0][i],arr[1][i]});
        }
        Collections.sort(list,(a,b)->{
            return b[1]-a[1];
        });
        list.forEach(a->{
            System.out.println(a[0]+" "+a[1]);
        });
        int addSum=0;
        int minX=list.get(m-1)[1];
        for (int i = 0; i < m; i++) {
            addSum+=list.get(i)[0];
        }
        int res=addSum*minX;
        for(int i=1,j=m+1;j<n;i++,j++){
            addSum+=list.get(j)[0]-list.get(j-1)[0];
            minX=Math.min(minX,list.get(j)[1]);
            int p=addSum*minX;
            System.out.println(p);
            res=Math.max(res,p);
        }
        System.out.println(res);
    }
}
